using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;

using Common;

using GrpcClient.Interfaces;
using GrpcClient.Services;
using GrpcClient.Utility;

using TextCopy;

namespace GrpcClient.Managers
{
    public class LicenseManager : Singleton<LicenseManager>, IManager
    {
        public event Action<string>? PrintRegistryCodeEvent;

        public async Task GenerateLicenseKey(string key, int role, int day)
        {
            DateTime licenseTime = DateTime.Now.AddDays(day);
            string date = $"{licenseTime:yyyyMMdd}";
            string messageId = LicenseService.Instance.LicenseSync(key, role, date);

            await CommonUtility.Wait(LicenseService.Instance.MessageCache[messageId]);
        }

        public void EncryptLicenseKey(string key)
        {
            Console.WriteLine(key);
            if (PrintRegistryCodeEvent != null)
            {
                PrintRegistryCodeEvent.Invoke(key);
            }
            ClipboardService.SetText(key);
        }

        public void Start()
        {

        }

        public void Stop()
        {

        }
    }
}
